package com.ruoyi.im.service.impl;

import com.ruoyi.im.entity.IMGroup;
import com.ruoyi.im.entity.IMGroupMember;
import com.ruoyi.im.mapper.IMGroupMapper;
import com.ruoyi.im.mapper.IMGroupMemberMapper;
import com.ruoyi.im.service.IMGroupService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by wx on 2017/10/27.
 */
@Service
public class IMGroupServiceImpl implements IMGroupService {
    @Resource
    private IMGroupMapper groupMapper;
    @Resource
    private IMGroupMemberMapper groupMemberMapper;

    @Override
    public IMGroup getGroupById(Long userId) {
       return groupMapper.selectGroupById(userId);
    }

    @Override
    public IMGroup getGroupByName(String userName) {
       return groupMapper.selectGroupByName(userName);
    }

    @Override
    public List<IMGroup> getAllGroup() {
        return groupMapper.selectAllGroup();
    }

    @Override
    public long addGroup(IMGroup user) {
        return groupMapper.insertSelective(user);
    }

    @Override
    public Boolean deleteGroup(Long id) {
        IMGroupMember groupMember = new IMGroupMember();
        groupMember.setGroupId(id);
        groupMember.setStatus(1);
        groupMemberMapper.updateByPrimaryKeySelective(groupMember);
        return groupMapper.deleteByPrimaryKey(id) > 0;
    }


    @Override
    public Boolean updateGroup(IMGroup user) {
        return groupMapper.updateByPrimaryKeySelective(user) > 0;
    }

    @Override
    public IMGroup getAreaGroup(String groupName) {
        return groupMapper.selectAreaGroup(groupName);
    }

}
